$(document).ready(function(){
						  
	//global vars
	var form = $("#customForm");
	var emp_id = $("#emp_id");
	var empInfo = $("#empInfo");
	var quick_email = $("#quick_email");
	var emailInfo = $("#emailInfo");	
	var quick_name = $("#quick_name");
	var nameInfo = $("#nameInfo");
	var vcode = $("#vcode");
	var vcodeInfo = $("#vcodeInfo");
	
	//On blur
	emp_id.blur(validateEmpid);
	quick_email.blur(validateEmail);
	quick_name.blur(validateName);
	
	vcode.blur(validatevcode);
	
	//On key press
	emp_id.keyup(validateEmpid);
	quick_name.keyup(validateName);
    
	vcode.keyup(validatevcode);
	
	//On Submitting
	form.submit(function(){
						 
		if(validateEmpid() & validateEmail() & validateName() || validatevcode())
			return true
		else
			return false;
	});
	
	//validation functions
	function validateEmpid(){
		//if it's NOT valid
		if (emp_id.val() == "" || emp_id.val() == null){
			emp_id.addClass("error");
			empInfo.text("Please Enter Valid Emp id!");
			empInfo.addClass("error");
			return false;
		}
		//if it's valid
		else{
			emp_id.removeClass("error");
			empInfo.text("");
			empInfo.removeClass("error");
			return true;
		}
	}
	
	
	function validateEmail(){
		//testing regular expression
		var a = $("#quick_email").val();
		var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
		//if it's valid email
		if(filter.test(a)){
			quick_email.removeClass("error");
			emailInfo.text("");
			emailInfo.removeClass("error");
			return true;
		}
		//if it's NOT valid
		else{
			quick_email.addClass("error");
			emailInfo.text("Valid E-mail please!");
			emailInfo.addClass("error");
			return false;
		}
	}
	function validateName(){
		//if it's NOT valid
		if (quick_name.val() == "" || quick_name.val() == null || !isNaN(quick_name.val()) || (quick_name.val().trim().length<4) )
		{
			quick_name.addClass("error");
			nameInfo.text("Enter name more than 4 letters!");
			nameInfo.addClass("error");
			return false;
		}
		
		//if it's valid
		else{
			quick_name.removeClass("error");
			nameInfo.text("");
			nameInfo.removeClass("error");
			return true;
		}
	}
	
	function validatevcode(){
		//if it's NOT valid
		if (vcode.val() == "" || vcode.val() == null){
			vcode.addClass("error");
			vcodeInfo.text("Please Enter Valid Code...!");
			vcodeInfo.addClass("error");
			return false;
		}
		//if it's valid
		else{
			vcode.removeClass("error");
			vcodeInfo.text("");
			vcodeInfo.removeClass("error");
			return true;
		}
	}

});